<?php
include "include/config.inc.php";
if(!isset($_SESSION['s_activId']))
{
  header('location:checkLogin.php');
}
$today = date("Y-m-d");
$totalAmountDr = 0;
$totalAmountCr = 0;
$rojmelArryDr = array();
$rojmelArryCr = array();
$i = 0;
$j = 0;
$selectForDisplay = "SELECT rojmelId, date, amount,debitCredit, accountName, loanId, note
                       FROM rojmel
                       JOIN account ON rojmel.accountId = account.accountId
                      WHERE date = '".$today."' ";
if(isset($_POST['submitDate']))
{
  $currentDate = $_POST['curDateYear']."-".$_POST['curDateMonth']."-".$_POST['curDateDay'];
  $selectForDisplay = "SELECT rojmelId, date, amount,debitCredit, accountName, loanId, note
                         FROM rojmel
                         JOIN account ON rojmel.accountId = account.accountId
                        WHERE date = '".$currentDate."' ";
}
$selectForDisplayRes = mysql_query($selectForDisplay);
while($selectForDisplayRow = mysql_fetch_array($selectForDisplayRes))
{
	if($selectForDisplayRow['debitCredit'] == 'Cr')
	{
	  $totalAmountCr = $totalAmountCr + $selectForDisplayRow['amount'];
	  $rojmelArryCr[$i]['rojmelId']    = $selectForDisplayRow['rojmelId'];
    $rojmelArryCr[$i]['date']        = date('d-m-Y',strtotime($selectForDisplayRow['date']));
    $rojmelArryCr[$i]['amount']      = $selectForDisplayRow['amount'];
    $rojmelArryCr[$i]['debitCredit'] = $selectForDisplayRow['debitCredit'];
    $rojmelArryCr[$i]['accountName'] = $selectForDisplayRow['accountName'];
    $rojmelArryCr[$i]['loanId']      = $selectForDisplayRow['loanId'];
    $rojmelArryCr[$i]['note']        = $selectForDisplayRow['note'];
    $i++;
  }
  else
  {
    $totalAmountDr = $totalAmountDr + $selectForDisplayRow['amount'];
    $rojmelArryDr[$j]['rojmelId']    = $selectForDisplayRow['rojmelId'];
    $rojmelArryDr[$j]['date']        = date('d-m-Y',strtotime($selectForDisplayRow['date']));
    $rojmelArryDr[$j]['amount']      = $selectForDisplayRow['amount'];
    $rojmelArryDr[$j]['debitCredit'] = $selectForDisplayRow['debitCredit'];
    $rojmelArryDr[$j]['accountName'] = $selectForDisplayRow['accountName'];
    $rojmelArryDr[$j]['loanId']      = $selectForDisplayRow['loanId'];
    $rojmelArryDr[$j]['note']        = $selectForDisplayRow['note'];
    $j++; 
  }
  
}
include("bottom.php");
$smarty->assign("today",$today);
$smarty->assign("rojmelArryDr",$rojmelArryDr);
$smarty->assign("rojmelArryCr",$rojmelArryCr);
$smarty->assign("totalAmountCr",$totalAmountCr);
$smarty->assign("totalAmountDr",$totalAmountDr);
$smarty->display('rojmel.tpl');  
?>